// date.cpp
// Implementation of the Date class

#include "date.h"

int Date::day() const
{
	return _day;
}

Month Date::month() const
{
	// convert the integer _month to the enumeration type Month
	return static_cast<Month>(_month);
}

int Date::year() const
{
	return _year;
}

bool Date::isLeapYear() const
{
	if ( _year % 4 != 0) return false;
	else {
		if ( _year % 100 != 0 ) return true;
		else 
			if ( _year % 400 != 0 ) return false;
			else return true;
	}
}

int Date::daysInMonth() const
{
	switch (_month) {
		case January: 
		case March: 
		case May: 
		case July:
		case August: 
		case October: 
		case December:
			return 31;	
		case April: 
		case June: 
		case September:
		case November:
			return 30;	
		case February:
			if ( isLeapYear() ) return 29;
			else return 28;
		default:
			// should never reach here
			assert(false);
	}
}

// Note, this function is not part of the Date class
void printDate(const Date& date)
{
	cout << date.day() << "/"
		<< date.month() << "/"
		<< date.year()
		<< endl;
}

